/**
 * @Description:TODO
 * @author: Jiahang 
 */
package com.hdd.hll.common.utils;

import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;


public class SwaggerUtils {
	public static Docket common(String name, String url) {
		
		
		ParameterBuilder ticketPar = new ParameterBuilder();
		List<Parameter> pars = new ArrayList<Parameter>();
		ticketPar.name("Authorization").description("Authorization").modelRef(new ModelRef("string")).parameterType("header")
				.required(false).build(); // header中的ticket参数非必填，传空也可以
		pars.add(ticketPar.build()); // 根据每个方法名也知道当前方法在设置什么参数
		return new Docket(DocumentationType.SWAGGER_2).groupName(name).genericModelSubstitutes(DeferredResult.class)
				.useDefaultResponseMessages(false).apiInfo(apiInfo()).pathMapping("/").select()
				.apis(RequestHandlerSelectors.basePackage(url)).paths(PathSelectors.any()).build()
				.globalOperationParameters(pars);

	}

	private static ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("陕西中矿科技有限公司API接口").description("陕西中矿科技有限公司API接口")
				.termsOfServiceUrl("http://www.zkkjgs.com/").version("2.0.0").build();
	}
}
